import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/about',
    name: 'About',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  },
  {
    path: '/product',
    name: 'product',
    component: () => import(/* webpackChunkName: "about" */ '../views/product.vue')
  },
  {
    path: '/releaseNeeds',
    name: 'releaseNeeds',
    component: () => import(/* webpackChunkName: "about" */ '../views/releaseNeeds.vue')
  },
  {
    path: '/releaseProducts',
    name: 'releaseProducts',
    component: () => import(/* webpackChunkName: "about" */ '../views/releaseProducts.vue')
  },
  {
    path: '/login',
    name: 'login',
    component: () => import(/* webpackChunkName: "about" */ '../views/login.vue')
  },
  {
    path: '/register',
    name: 'register',
    component: () => import(/* webpackChunkName: "about" */ '../views/register.vue')
  },
  {
    path: '/search',
    name: 'search',
    component: () => import(/* webpackChunkName: "about" */ '../views/search.vue')
  },
  {
    path: '/myCart',
    name: 'myCart',
    component: () => import(/* webpackChunkName: "about" */ '../views/myCart.vue')
  },
  {
    path: '/myOrder',
    name: 'myOrder',
    component: () => import(/* webpackChunkName: "about" */ '../views/myOrder.vue')
  },
  {
    path: '/mySpace',
    name: 'mySpace',
    component: () => import(/* webpackChunkName: "about" */ '../views/mySpace.vue')
  },
  {
    path: '/myMsg',
    name: 'myMsg',
    component: () => import(/* webpackChunkName: "about" */ '../views/myMsg.vue')
  },
  {
    path: '/buyItNow',
    name: 'buyItNow',
    component: () => import(/* webpackChunkName: "about" */ '../views/buyItNow.vue')
  },
  {
    path: '/products',
    name: 'products',
    component: () => import(/* webpackChunkName: "about" */ '../views/products.vue')
  },
  {
    path: '/needMarket',
    name: 'needMarket',
    component: () => import(/* webpackChunkName: "about" */ '../views/needMarket.vue')
  },
  {
    path: '/userInfo',
    name: 'userInfo',
    component: () => import(/* webpackChunkName: "about" */ '../views/userInfo.vue')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes,
  scrollBehavior (to, from, savedPosition) { //解决跳转下一个页面底部的方法
    if (savedPosition) {
      return savedPosition
    } else {
      return { x: 0, y: 0 }
    }
 }
})

export default router
